
package com.zhomboin.mail;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;

import java.util.Arrays;

/**
 * @author zhboom
 * @date 2024/11/20 21:19
 */
@Slf4j
@Controller
public class MailService {

    @Autowired
    private JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String from;

    public void sendSimpleMail(String[] to, String[] cc, String subject, String context) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(to);
        message.setCc(cc);
        message.setSubject(subject);
        message.setText(context);
        message.setFrom(from);

        mailSender.send(message);
        log.info("send mail success. \n【subject】{}\n【to】{}\n【context】{}", subject, Arrays.toString(to), context);
    }
}
